//
// Created by lenovo on 2024/8/12.
//

#ifndef TREELIB_TREE_MULTITREE_LIMITTREE_H
#define TREELIB_TREE_MULTITREE_LIMITTREE_H
#include "./TemplateTree.h"
#include "./TemplateNode.h"
namespace TREE{
    template <typename T , size_t _Capacity >
    class LimitNode : public TemplateNode<T>{
    public :
        LimitNode(T data) {
            this->_data = data ;
        }

        Node<T>*        parent      () override ;
        virtual bool    _acceptable (Node<T>* node) ;
        void            setChild    (T data , int n) override ;
        void            setChild    (Node<T>* node , int n) override ;
        int             capacity    ()  const override ;
    };

    template<typename T , size_t _Capacity>
    void LimitNode<T , _Capacity>::setChild(Node<T> *node, int n) {
        if (this->width() >= this->capacity())
            return ;
        else
            TemplateNode<T>::setChild(node , n);
    }

    template<typename T , size_t _Capacity>
    int LimitNode<T , _Capacity>::capacity() const {
        return _Capacity ;
    }

    template<typename T, size_t _Capacity>
    void LimitNode<T , _Capacity>::setChild(T data, int n) {
        setChild(
                new LimitNode<T , _Capacity>(data) ,
                n
        );
    }

    template<typename T, size_t _Capacity>
    bool LimitNode<T , _Capacity>::_acceptable(Node<T> *node) {
        if (node->capacity() == this->capacity())
            return true ;
        return false ;
    }

    template<typename T, size_t _Capacity>
    Node<T> *LimitNode<T , _Capacity>::parent() {
        return nullptr;
    }

    template <typename T , size_t _Capacity>
    using LimitTree = TemplateTree<LimitNode<T , _Capacity> > ;

    template <typename T >
    using L4Tree = LimitTree<T , 4 > ;

    template <typename T>
    using L8Tree = LimitTree<T,8> ;
}
#endif //TREELIB_TREE_MULTITREE_LIMITTREE_H
